package com.mouse.util;

import java.sql.*;

/**
 * @Auther: liu
 * @Date: 2024/5/2312:14
 */
public class JDBCUtil {

        private static JDBCUtil jdbcUtil = null;

        private JDBCUtil(){

        }

        public static JDBCUtil getJdbcDemo(){
            if (jdbcUtil ==null){
                jdbcUtil = new JDBCUtil();
            }
            return jdbcUtil;
        }



        static {
       try{
           Class.forName("com.mysql.jdbc.Driver");
       }catch (Exception e){
           e.printStackTrace();
       }
        }
//获取连接
    public Connection getConnection() throws SQLException {

            return DriverManager.getConnection(PropertiesUtil.getPropertiesUtil().getValue("url"), PropertiesUtil.getPropertiesUtil().getValue("username"), PropertiesUtil.getPropertiesUtil().getValue("pwd"));

       /* String url =  "jdbc:mysql://127.0.0.1:3306/qq";
        String username = "root";
        String password = "123456";*/}


    public void closeConnection(ResultSet resultSet,Statement statement,Connection connection) {
            try {
                resultSet.close();
            }catch (Exception e){
                e.printStackTrace();
            }finally {
                try {
                    statement.close();
                }catch (Exception e){
                    e.printStackTrace();
                }
                finally {
                    try{
                        statement.close();
                }catch (Exception e){
                        e.printStackTrace();
                    }
                }

            }

    }





}
